
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>静态查找表 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="动态查找表.html" />
    
    
    <link rel="prev" href="查找.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    数据结构（C语言版） 复习总结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    第一章 绪论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2/chapter2.html">
            
                <a href="../chapter2/chapter2.html">
            
                    
                    第二章 线性表
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/顺序表.html">
            
                <a href="../chapter2/顺序表.html">
            
                    
                    线性表的顺序表示和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter2/链表.html">
            
                <a href="../chapter2/链表.html">
            
                    
                    线性表的链式表示和实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter3/chapter3.html">
            
                <a href="../chapter3/chapter3.html">
            
                    
                    第三章 栈和队列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter3/栈.html">
            
                <a href="../chapter3/栈.html">
            
                    
                    抽象数据类型栈的定义和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter3/队列.html">
            
                <a href="../chapter3/队列.html">
            
                    
                    抽象数据类型队列的定义和实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    第四章 串
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter4/串类型.html">
            
                <a href="../chapter4/串类型.html">
            
                    
                    串类型的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter4/串的表示和实现.html">
            
                <a href="../chapter4/串的表示和实现.html">
            
                    
                    串的表示和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter4/串的模式匹配算法.html">
            
                <a href="../chapter4/串的模式匹配算法.html">
            
                    
                    串的模式匹配算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    第五章 数组和广义表
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter5/数组的定义.html">
            
                <a href="../chapter5/数组的定义.html">
            
                    
                    数组的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter5/矩阵的压缩存储.html">
            
                <a href="../chapter5/矩阵的压缩存储.html">
            
                    
                    矩阵的压缩存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter5/广义表.html">
            
                <a href="../chapter5/广义表.html">
            
                    
                    广义表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    第六章 树和二叉树
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter6/树.html">
            
                <a href="../chapter6/树.html">
            
                    
                    树的定义与基本术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter6/二叉树.html">
            
                <a href="../chapter6/二叉树.html">
            
                    
                    二叉树
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.2.1" data-path="../chapter6/二叉树的二叉链表实现.html">
            
                <a href="../chapter6/二叉树的二叉链表实现.html">
            
                    
                    二叉树的二叉链表实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter6/遍历二叉树和线索二叉树.html">
            
                <a href="../chapter6/遍历二叉树和线索二叉树.html">
            
                    
                    遍历二叉树和线索二叉树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter6/树和森林.html">
            
                <a href="../chapter6/树和森林.html">
            
                    
                    树和森林
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter6/赫夫曼树.html">
            
                <a href="../chapter6/赫夫曼树.html">
            
                    
                    赫夫曼树
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                    第七章 图
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter7/图.html">
            
                <a href="../chapter7/图.html">
            
                    
                    图的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter7/图的存储结构.html">
            
                <a href="../chapter7/图的存储结构.html">
            
                    
                    图的存储结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter7/图的遍历.html">
            
                <a href="../chapter7/图的遍历.html">
            
                    
                    图的遍历
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter7/最小生成树.html">
            
                <a href="../chapter7/最小生成树.html">
            
                    
                    最小生成树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter7/有向无环图.html">
            
                <a href="../chapter7/有向无环图.html">
            
                    
                    有向无环图的应用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="查找.html">
            
                <a href="查找.html">
            
                    
                    第八章 查找
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.9.1" data-path="静态查找表.html">
            
                <a href="静态查找表.html">
            
                    
                    静态查找表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="动态查找表.html">
            
                <a href="动态查找表.html">
            
                    
                    动态查找表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="哈希表.html">
            
                <a href="哈希表.html">
            
                    
                    哈希表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter9/内部排序.html">
            
                <a href="../chapter9/内部排序.html">
            
                    
                    第九章 内部排序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter9/插入排序.html">
            
                <a href="../chapter9/插入排序.html">
            
                    
                    插入排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter9/选择排序.html">
            
                <a href="../chapter9/选择排序.html">
            
                    
                    选择排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter9/快速排序.html">
            
                <a href="../chapter9/快速排序.html">
            
                    
                    快速排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter9/归并排序和基数排序.html">
            
                <a href="../chapter9/归并排序和基数排序.html">
            
                    
                    归并排序和基数排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter9/排序方法的比较.html">
            
                <a href="../chapter9/排序方法的比较.html">
            
                    
                    排序方法的比较
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >静态查找表</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x9759;&#x6001;&#x67E5;&#x627E;&#x8868;">&#x9759;&#x6001;&#x67E5;&#x627E;&#x8868;</h2>
<h3 id="&#x987A;&#x5E8F;&#x8868;&#x7684;&#x67E5;&#x627E;">&#x987A;&#x5E8F;&#x8868;&#x7684;&#x67E5;&#x627E;</h3>
<p><strong>&#x987A;&#x5E8F;&#x67E5;&#x627E;</strong>&#xFF1A;&#x4ECE;&#x8868;&#x4E2D;&#x7684;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x8BB0;&#x5F55;&#x5F00;&#x59CB;&#xFF0C;&#x9010;&#x4E2A;&#x8FDB;&#x884C;&#x8BB0;&#x5F55;&#x7684;&#x5173;&#x952E;&#x5B57;&#x548C;&#x7ED9;&#x5B9A;&#x503C;&#x7684;&#x6BD4;&#x8F83;&#xFF0C;&#x82E5;&#x67D0;&#x4E2A;&#x8BB0;&#x5F55;&#x7684;&#x5173;&#x952E;&#x5B57;&#x548C;&#x7ED9;&#x5B9A;&#x503C;&#x6BD4;&#x8F83;&#x76F8;&#x7B49;&#xFF0C;&#x5219;&#x67E5;&#x627E;&#x6210;&#x529F;&#xFF0C;&#x627E;&#x5230;&#x6240;&#x67E5;&#x8BB0;&#x5F55;&#xFF1B;&#x53CD;&#x4E4B;&#xFF0C;&#x82E5;&#x76F4;&#x81F3;&#x7B2C;&#x4E00;&#x4E2A;&#x8BB0;&#x5F55;&#xFF0C;&#x5176;&#x5173;&#x952E;&#x5B57;&#x548C;&#x7ED9;&#x5B9A;&#x503C;&#x6BD4;&#x8F83;&#x90FD;&#x4E0D;&#x76F8;&#x7B49;&#xFF0C;&#x5219;&#x8868;&#x660E;&#x8868;&#x4E2D;&#x6CA1;&#x6709;&#x6240;&#x67E5;&#x8BB0;&#x5F55;&#xFF0C;&#x67E5;&#x627E;&#x4E0D;&#x6210;&#x529F;&#x3002;</p>
<blockquote>
<p>&#x987A;&#x5E8F;&#x67E5;&#x627E;&#x65E0;&#x8BBA;&#x8BB0;&#x5F55;&#x662F;&#x5426;&#x6309;&#x5173;&#x952E;&#x5B57;&#x6709;&#x5E8F;&#x5747;&#x53EF;&#x5E94;&#x7528;&#x3002;</p>
</blockquote>
<pre><code class="lang-C"><span class="hljs-comment">/**
 * &#x9759;&#x6001;&#x67E5;&#x627E;&#x8868;&#x7684;&#x987A;&#x5E8F;&#x5B58;&#x50A8;&#x7ED3;&#x6784;
 */</span>
<span class="hljs-keyword">typedef</span> <span class="hljs-keyword">struct</span>
{
    ElemType *elem; <span class="hljs-comment">// &#x6570;&#x636E;&#x5143;&#x7D20;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#x57FA;&#x5740;&#xFF0C;0 &#x53F7;&#x7A7A;&#x95F4;&#x7559;&#x7A7A;</span>
    <span class="hljs-keyword">int</span> length; <span class="hljs-comment">// &#x8868;&#x957F;&#x5EA6;</span>
}SSTable;

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">SearchSeq</span><span class="hljs-params">(SSTable ST, KeyType key)</span>
</span>{
    ST.elem[<span class="hljs-number">0</span>].key = key; <span class="hljs-comment">// &#x201C;&#x54E8;&#x5175;&#x201D;</span>
    <span class="hljs-keyword">for</span>(i = ST.length; ST.elem[i].key != key; --i); <span class="hljs-comment">// &#x4ECE;&#x540E;&#x5F80;&#x524D;&#x627E;</span>
    <span class="hljs-keyword">return</span> i;
}
</code></pre>
<p>&#x5728;&#x67E5;&#x627E;&#x4E4B;&#x524D;&#x5C06; <code>ST.elem[0]</code> &#x7684;&#x5173;&#x952E;&#x5B57;&#x8D4B;&#x503C; <code>key</code>&#xFF0C;&#x76EE;&#x7684;&#x5728;&#x4E8E;&#x514D;&#x53BB;&#x67E5;&#x627E;&#x8FC7;&#x7A0B;&#x4E2D;&#x6BCF;&#x4E00;&#x6B65;&#x90FD;&#x8981;&#x68C0;&#x6D4B;&#x6574;&#x4E2A;&#x8868;&#x662F;&#x5426;&#x67E5;&#x627E;&#x5B8C;&#x6BD5;&#x3002;</p>
<p>&#x5728;&#x7B49;&#x6982;&#x7387;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x987A;&#x5E8F;&#x67E5;&#x627E;&#x7684;&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;&#x4E3A;</p>
<center><img src="&#x987A;&#x5E8F;&#x67E5;&#x627E;&#x7684;&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;.png"></center>

<blockquote>
<p>&#x5F53;&#x67E5;&#x627E;&#x4E0D;&#x6210;&#x529F;&#x65F6;&#x548C;&#x7ED9;&#x5B9A;&#x503C;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#x7684;&#x5173;&#x952E;&#x5B57;&#x4E2A;&#x6570;&#x5747;&#x4E3A; <em>n+1</em>&#xFF0C;&#x6B64;&#x65F6; <em>P<sub>i</sub>=1/(2n)</em>&#xFF0C;&#x987A;&#x5E8F;&#x67E5;&#x627E;&#x7684;&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;&#x4E3A; <em>ASL<sub>SS</sub> = 3(n+1)/4</em>&#x3002;</p>
</blockquote>
<h3 id="&#x6298;&#x534A;&#x67E5;&#x627E;">&#x6298;&#x534A;&#x67E5;&#x627E;</h3>
<p><strong>&#x6298;&#x534A;&#x67E5;&#x627E;</strong>&#x9002;&#x7528;&#x4E8E;&#x987A;&#x5E8F;&#x5B58;&#x50A8;&#x7ED3;&#x6784;&#x7684;&#x6709;&#x5E8F;&#x8868;&#x7684;&#x67E5;&#x627E;&#xFF0C;&#x67E5;&#x627E;&#x8FC7;&#x7A0B;&#x662F;&#xFF1A;&#x5148;&#x786E;&#x5B9A;&#x5F85;&#x67E5;&#x8BB0;&#x5F55;&#x6240;&#x5728;&#x7684;&#x8303;&#x56F4;&#xFF08;&#x533A;&#x95F4;&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x9010;&#x6B65;&#x7F29;&#x5C0F;&#x8303;&#x56F4;&#x76F4;&#x5230;&#x627E;&#x5230;&#x6216;&#x627E;&#x4E0D;&#x5230;&#x8BE5;&#x8BB0;&#x5F55;&#x4E3A;&#x6B62;&#x3002;</p>
<p>&#x7B97;&#x6CD5;&#x63CF;&#x8FF0;&#xFF1A;&#x8BBE;&#x8868;&#x957F;&#x4E3A; <em>n</em>&#xFF0C;<em>low</em>&#x3001;<em>high</em> &#x548C; <em>mid</em> &#x5206;&#x522B;&#x6307;&#x5411;&#x5F85;&#x67E5;&#x5143;&#x7D20;&#x6240;&#x5728;&#x533A;&#x95F4;&#x7684;&#x4E0B;&#x754C;&#x3001;&#x4E0A;&#x754C;&#x548C;&#x4E2D;&#x95F4;&#x4F4D;&#x7F6E;&#xFF08;&#x5373; <em>mid</em>=(int) (<em>low</em>+<em>high</em>)/2&#xFF09;&#x3002;&#x521D;&#x59CB;&#x65F6;&#xFF0C;&#x4EE4; low=1&#x3001;high=n&#x3002;&#x9996;&#x5148;&#x4EE4;&#x67E5;&#x627E;&#x8303;&#x56F4;&#x4E2D;&#x95F4;&#x4F4D;&#x7F6E;&#x7684;&#x6570;&#x636E;&#x5143;&#x7D20;&#x7684;&#x5173;&#x952E;&#x5B57; <code>ST.elem[mid].key</code> &#x4E0E;&#x7ED9;&#x5B9A;&#x503C; <code>key</code> &#x76F8;&#x6BD4;&#x8F83;&#xFF0C;&#x82E5; key &lt; ST.elem[mid].key&#xFF0C;&#x5219; high=mid-1&#xFF1B;&#x82E5; k &gt; ST.elem[mid].key&#xFF0C;&#x5219; low=mid+1&#x3002;&#x91CD;&#x590D;&#x4E0A;&#x8FF0;&#x64CD;&#x4F5C;&#xFF0C;&#x76F4;&#x81F3;&#x65B0;&#x7684;&#x533A;&#x95F4;&#x4E2D;&#x95F4;&#x4F4D;&#x7F6E;&#x8BB0;&#x5F55;&#x7684;&#x5173;&#x952E;&#x5B57;&#x7B49;&#x4E8E;&#x7ED9;&#x5B9A;&#x503C;&#x6216;&#x8005;&#x67E5;&#x627E;&#x533A;&#x95F4;&#x7684;&#x5927;&#x5C0F;&#x5C0F;&#x4E8E;&#x96F6;&#x65F6;&#xFF08;&#x8868;&#x660E;&#x67E5;&#x627E;&#x4E0D;&#x6210;&#x529F;&#xFF09;&#x4E3A;&#x6B62;&#x3002;</p>
<pre><code class="lang-C"><span class="hljs-comment">/**
 * &#x6298;&#x534A;&#x67E5;&#x627E;&#x7684;&#x975E;&#x9012;&#x5F52;&#x7B97;&#x6CD5;
 */</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">SearchBin</span><span class="hljs-params">(SSTable ST, KeyType key)</span>
</span>{
    <span class="hljs-keyword">int</span> low = <span class="hljs-number">1</span>, high = ST.length; <span class="hljs-comment">// &#x7F6E;&#x533A;&#x95F4;&#x521D;&#x503C;</span>
    <span class="hljs-keyword">while</span> (low &lt;= high)
    {
        mid = (low + high) / <span class="hljs-number">2</span>;
        <span class="hljs-keyword">if</span> (key == ST.elem[mid].key)
        {
            <span class="hljs-keyword">return</span> mid;  <span class="hljs-comment">// &#x627E;&#x5F85;&#x67E5;&#x5143;&#x7D20;</span>
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (key &lt; ST.elem[mid].key)
        {
            high = mid - <span class="hljs-number">1</span>; <span class="hljs-comment">// &#x7EE7;&#x7EED;&#x5728;&#x524D;&#x534A;&#x533A;&#x95F4;&#x8FDB;&#x884C;&#x67E5;&#x627E;</span>
        }
        <span class="hljs-keyword">else</span>
        {
            low = mid + <span class="hljs-number">1</span>; <span class="hljs-comment">// &#x7EE7;&#x7EED;&#x5728;&#x540E;&#x534A;&#x533A;&#x95F4;&#x8FDB;&#x884C;&#x67E5;&#x627E;</span>
        }
  }
  <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; <span class="hljs-comment">// &#x987A;&#x5E8F;&#x8868;&#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x5F85;&#x67E5;&#x5143;&#x7D20;</span>
}

<span class="hljs-comment">/**
 * &#x6298;&#x534A;&#x67E5;&#x627E;&#x7684;&#x9012;&#x5F52;&#x7B97;&#x6CD5;
 */</span>
KeyType key; <span class="hljs-comment">// &#x65B9;&#x4FBF;&#x8D77;&#x89C1;&#xFF0C;&#x5C06;&#x67E5;&#x8BE2;&#x5173;&#x952E;&#x5B57;&#x8BBE;&#x7F6E;&#x4E3A;&#x5168;&#x5C40;&#x53D8;&#x91CF;</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">SearchBin</span><span class="hljs-params">(SSTable ST, <span class="hljs-keyword">int</span> low, <span class="hljs-keyword">int</span> high)</span>
</span>{
    <span class="hljs-keyword">if</span> (low &gt; high)
    {
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
    }
    <span class="hljs-keyword">else</span>
    {
        mid = (low + high) / <span class="hljs-number">2</span>;
        <span class="hljs-keyword">if</span> (key &lt; ST.elem[mid].key)
        {
            <span class="hljs-keyword">return</span> SearchBin(ST, low, mid - <span class="hljs-number">1</span>);
        }
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (key &gt; ST.elem[mid].key)
        {
            <span class="hljs-keyword">return</span> SearchBin(ST, mid + <span class="hljs-number">1</span>, high);
        }
        <span class="hljs-keyword">else</span>
        {
            <span class="hljs-keyword">return</span> mid;
        }
    }
}
</code></pre>
<p>&#x6298;&#x534A;&#x67E5;&#x627E;&#x6CD5;&#x5728;&#x67E5;&#x627E;&#x6210;&#x529F;&#x65F6;&#x548C;&#x7ED9;&#x5B9A;&#x503C;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#x7684;&#x5173;&#x952E;&#x5B57;&#x4E2A;&#x6570;&#x81F3;&#x591A;&#x4E3A; [log<sub>2</sub> n]+1&#xFF0C;&#x5F53;&#x5BF9;&#x8868;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x8BB0;&#x5F55;&#x7684;&#x67E5;&#x627E;&#x6982;&#x7387;&#x76F8;&#x540C;&#x65F6;&#xFF0C;&#x67E5;&#x627E;&#x6210;&#x529F;&#x65F6;&#x6298;&#x534A;&#x67E5;&#x627E;&#x7684;&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;&#x4E3A;</p>
<center><img src="&#x6298;&#x534A;&#x67E5;&#x627E;&#x7684;&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;.png"></center>

<h3 id="&#x7D22;&#x5F15;&#x987A;&#x5E8F;&#x8868;&#x7684;&#x67E5;&#x627E;">&#x7D22;&#x5F15;&#x987A;&#x5E8F;&#x8868;&#x7684;&#x67E5;&#x627E;</h3>
<p><strong>&#x5206;&#x5757;&#x67E5;&#x627E;</strong>&#x53C8;&#x53EB;&#x505A;&#x7D22;&#x5F15;&#x987A;&#x5E8F;&#x67E5;&#x627E;&#x3002;&#x5728;&#x6B64;&#x67E5;&#x627E;&#x6CD5;&#x4E2D;&#xFF0C;&#x9664;&#x8868;&#x672C;&#x8EAB;&#x4EE5;&#x5916;&#xFF0C;&#x5C1A;&#x9700;&#x8981;&#x5EFA;&#x7ACB;&#x4E00;&#x4E2A;&#x201C;&#x7D22;&#x5F15;&#x8868;&#x201D;&#xFF0C;&#x5C06;&#x8868;&#x4E2D; <em>n</em> &#x4E2A;&#x5143;&#x7D20;&#x5747;&#x5300;&#x5730;&#x5206;&#x6210;&#x5B50;&#x8868;&#xFF08;&#x5757;&#xFF09;&#x5BF9;&#x6BCF;&#x4E2A;&#x5B50;&#x8868;&#xFF08;&#x5757;&#xFF09;&#x5EFA;&#x7ACB;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x9879;&#xFF0C;&#x5176;&#x4E2D;&#x5305;&#x62EC;&#x4E24;&#x9879;&#x5185;&#x5BB9;&#xFF1A;&#x5173;&#x952E;&#x5B57;&#x9879;&#xFF08;&#x5176;&#x503C;&#x4E3A;&#x8BE5;&#x5B50;&#x8868;&#x5185;&#x7684;&#x6700;&#x5927;&#x5173;&#x952E;&#x5B57;&#xFF09;&#x548C;&#x6307;&#x9488;&#x9879;&#xFF08;&#x6307;&#x793A;&#x8BE5;&#x5B50;&#x8868;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x8BB0;&#x5F55;&#x5728;&#x8868;&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;&#xFF09;&#x3002;&#x6BCF;&#x5757;&#x6709; S &#x4E2A;&#x8BB0;&#x5F55;&#xFF0C;&#x5757;&#x95F4;&#x6309;&#x5927;&#x5C0F;&#x6392;&#x5E8F;&#xFF08;&#x5206;&#x5757;&#x6709;&#x5E8F;&#xFF09;&#xFF0C;&#x5757;&#x5185;&#x5143;&#x7D20;&#x4E0D;&#x6392;&#x5E8F;&#xFF08;&#x6216;&#x6709;&#x5E8F;&#xFF09;&#x3002;</p>
<blockquote>
<p><strong>&#x5206;&#x5757;&#x6709;&#x5E8F;</strong>&#xFF1A;&#x6307;&#x7684;&#x662F;&#x7B2C;&#x4E8C;&#x4E2A;&#x5B50;&#x8868;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x8BB0;&#x5F55;&#x5747;&#x5927;&#x4E8E;&#x7B2C;&#x4E00;&#x4E2A;&#x5B50;&#x8868;&#x4E2D;&#x7684;&#x6700;&#x5927;&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x7B2C;&#x4E09;&#x4E2A;&#x5B50;&#x8868;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x8BB0;&#x5F55;&#x5747;&#x5927;&#x4E8E;&#x7B2C;&#x4E8C;&#x4E2A;&#x5B50;&#x8868;&#x4E2D;&#x7684;&#x6700;&#x5927;&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x2026;&#x2026;&#xFF0C;&#x4EE5;&#x6B64;&#x7C7B;&#x63A8;&#x3002;</p>
</blockquote>
<p>&#x67E5;&#x627E;&#x65F6;&#xFF0C;&#x7D22;&#x5F15;&#x9879;&#x4F7F;&#x7528;&#x6298;&#x534A;&#x67E5;&#x627E;&#xFF0C;&#x5757;&#x4E2D;&#x8BB0;&#x5F55;&#x662F;&#x4EFB;&#x610F;&#x6392;&#x5E8F;&#x7684;&#xFF0C;&#x5728;&#x5757;&#x4E2D;&#x4F7F;&#x7528;&#x987A;&#x5E8F;&#x67E5;&#x627E;&#x3002;</p>
<p>&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E3A;&#x8FDB;&#x884C;&#x5206;&#x5757;&#x67E5;&#x627E;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x957F;&#x5EA6;&#x4E3A; <em>n</em> &#x7684;&#x8868;&#x5747;&#x5300;&#x5730;&#x5206;&#x6210; <em>b</em> &#x5757;&#xFF0C;&#x6BCF;&#x5757;&#x542B;&#x6709; <em>s</em> &#x4E2A;&#x8BB0;&#x5F55;&#xFF0C;&#x5373; <em>b=n/s</em>&#xFF1B;&#x53C8;&#x5047;&#x5B9A;&#x8868;&#x4E2D;&#x6BCF;&#x4E2A;&#x8BB0;&#x5F55;&#x7684;&#x67E5;&#x627E;&#x6982;&#x7387;&#x76F8;&#x540C;&#xFF0C;&#x5219;&#x6BCF;&#x5757;&#x67E5;&#x627E;&#x7684;&#x6982;&#x7387;&#x4E3A; <em>1/b</em>&#xFF0C;&#x5757;&#x4E2D;&#x6BCF;&#x4E2A;&#x8BB0;&#x5F55;&#x7684;&#x67E5;&#x627E;&#x6982;&#x7387;&#x4E3A; <em>1/s</em>&#x3002;&#x82E5;&#x4F7F;&#x7528;&#x6298;&#x534A;&#x67E5;&#x627E;&#x786E;&#x5B9A;&#x6240;&#x5728;&#x7684;&#x5757;&#xFF0C;&#x5219;&#x5206;&#x5757;&#x67E5;&#x627E;&#x7684;&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;&#x4E3A;</p>
<center><img src="&#x7D22;&#x5F15;&#x67E5;&#x627E;&#x7684;&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;.png"></center>

<h3 id="&#x672C;&#x8282;&#x4E09;&#x79CD;&#x67E5;&#x627E;&#x65B9;&#x6CD5;&#x7684;&#x6BD4;&#x8F83;">&#x672C;&#x8282;&#x4E09;&#x79CD;&#x67E5;&#x627E;&#x65B9;&#x6CD5;&#x7684;&#x6BD4;&#x8F83;</h3>
<table>
<thead>
<tr>
<th style="text-align:center"></th>
<th>&#x987A;&#x5E8F;&#x67E5;&#x627E;</th>
<th>&#x6298;&#x534A;&#x67E5;&#x627E;</th>
<th>&#x5206;&#x5757;&#x67E5;&#x627E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">&#x5E73;&#x5747;&#x67E5;&#x627E;&#x957F;&#x5EA6;</td>
<td>&#x6700;&#x5927;</td>
<td>&#x6700;&#x5C0F;</td>
<td>&#x4E24;&#x8005;&#x4E4B;&#x95F4;</td>
</tr>
<tr>
<td style="text-align:center">&#x8868;&#x7ED3;&#x6784;</td>
<td>&#x6709;&#x5E8F;&#x548C;&#x65E0;&#x5E8F;&#x8868;</td>
<td>&#x6709;&#x5E8F;&#x8868;</td>
<td>&#x5206;&#x5757;&#x6709;&#x5E8F;</td>
</tr>
<tr>
<td style="text-align:center">&#x652F;&#x6301;&#x7684;<br>&#x5B58;&#x50A8;&#x7ED3;&#x6784;</td>
<td>&#x987A;&#x5E8F;&#x8868;<br>&#x94FE;&#x8868;</td>
<td>&#x987A;&#x5E8F;&#x8868;</td>
<td>&#x987A;&#x5E8F;&#x8868;<br>&#x94FE;&#x8868;</td>
</tr>
</tbody>
</table>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="查找.html" class="navigation navigation-prev " aria-label="Previous page: 第八章 查找">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="动态查找表.html" class="navigation navigation-next " aria-label="Next page: 动态查找表">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"静态查找表","level":"1.9.1","depth":2,"next":{"title":"动态查找表","level":"1.9.2","depth":2,"path":"chapter8/动态查找表.md","ref":"chapter8/动态查找表.md","articles":[]},"previous":{"title":"第八章 查找","level":"1.9","depth":1,"path":"chapter8/查找.md","ref":"chapter8/查找.md","articles":[{"title":"静态查找表","level":"1.9.1","depth":2,"path":"chapter8/静态查找表.md","ref":"chapter8/静态查找表.md","articles":[]},{"title":"动态查找表","level":"1.9.2","depth":2,"path":"chapter8/动态查找表.md","ref":"chapter8/动态查找表.md","articles":[]},{"title":"哈希表","level":"1.9.3","depth":2,"path":"chapter8/哈希表.md","ref":"chapter8/哈希表.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter8/静态查找表.md","mtime":"2018-08-26T10:22:50.227Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-09-02T10:05:33.540Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

